//登录
let express = require('express');
let path = require('path');
let mysql = require('mysql');
//引入自定义模块
let user = require('../model/user');
let order = require('../model/order');

var router = express.Router();


router.get('/',function(req,res,next){
    res.sendStatus(404);
});
/**
 *登录验证功能
 */
router.post('/',function(req,res) {
    let name = req.body.username;
    let pw = req.body.password;
    user.search(name,pw,function (result){
        if(result.length === 1){
            user.searchID(name,function (result){
                token = user.createToken(result[0].userID,{expiresIn:100});//生成token
                res.send({loginStatus:0,userID:result[0].userID,token:token});
            })
        }
        else
            res.send({loginStatus:1});
    })
})

module.exports = router;
